﻿using System;
using System.Collections.Generic;
using System.Text;

using cosoware.RayTracer.Math;

namespace cosoware.RayTracer.Geometry
{
    /// <summary>
    /// The point primitive.
    /// </summary>
    public struct Coordinate
    {
        /// <summary>
        /// The coordinates matrix.
        /// </summary>
        private readonly Matrix _matrix;

        /// <summary>
        /// Initializes a new instance of the <see cref="Point"/> class.
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="z">The z coordinate.</param>
        Coordinate(double x, double y, double z)
        {
            _matrix = new Matrix(1, 4);
            _matrix[0, 0] = x;
            _matrix[0, 1] = y;
            _matrix[0, 2] = z;
            _matrix[0, 3] = 1.0f;
        }

        /// <summary>
        /// Gets the X coordinate.
        /// </summary>
        /// <value>The X coordinate.</value>
        public double X
        {
            get { return _matrix[0, 0]; }
        }

        /// <summary>
        /// Gets the Y coordinate.
        /// </summary>
        /// <value>The Y coordinate.</value>
        public double Y
        {
            get { return _matrix[0, 1]; }
        }

        /// <summary>
        /// Gets the Z coordinate.
        /// </summary>
        /// <value>The Z coordinate.</value>
        public double Z
        {
            get { return _matrix[0, 2]; }
        }

        /// <summary>
        /// Get the matrix representation.
        /// </summary>
        /// <returns></returns>
        public Matrix GetMatrix()
        {
            return _matrix;
        }

        public void InitMatrixRow(ref Matrix matrix, int index)
        {
            matrix[index, 0] = X;
            matrix[index, 1] = Y;
            matrix[index, 2] = Z;
            matrix[0, 3] = 1.0;
        }
    }
}
